package com.avic.rong.wedgit.customWedgit;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import com.avic.rong.MainActivity;
import com.avic.rong.MyApplication;
import com.avic.rong.R;
import com.avic.rong.utils.DensityUtils;
import com.example.minato.minastore.utils.AppUtils;

import butterknife.ButterKnife;
import butterknife.OnClick;


public class NavigatorPopup extends PopupWindow{

    private View contentView;
    private StateButton btn_commit;
    private Context context;

    public NavigatorPopup(final Activity context) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contentView = inflater.inflate(R.layout.popup_filter_attr, null);
        ButterKnife.bind(this,contentView);
        this.context = context;


        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        this.setContentView(contentView);
        this.setWidth(DensityUtils.dip2px(context,120));
        this.setHeight(DensityUtils.dip2px(context,250));

        ColorDrawable dw = new ColorDrawable(00000000);
        this.setBackgroundDrawable(dw);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        this.update();
    }

    @OnClick({R.id.ll_shouye,R.id.ll_sousuo,R.id.ll_rongrong,R.id.ll_kefu})
    public void clickNavigator(View view){
        int viewId = view.getId();
        this.dismiss();
        switch (viewId){
            case R.id.ll_shouye:
                break;
            case R.id.ll_sousuo://搜索
//                context.startActivity(SearchIndexActivity.queryIntent(context, AppUtils.BASE_URL + "app/searchIndex?type=0",UserMoneyListActivity.ARG_FROM_MONEY_LIST));
                break;
            case R.id.ll_rongrong://我的融融
                if(context instanceof MainActivity){
                    MainActivity mainActivity = (MainActivity)context;
//                    mainActivity.switchFragment(R.id.rbtn_mine);
                }
                break;
            case R.id.ll_kefu://在线客服
//                http://app1.rongrong.huazhi365.com/app/cservice?userId=212901
                String tempUrl = AppUtils.BASE_URL + "app/cservice?userId=" + MyApplication.getInstance().userLoginBean.getUserId();
                Intent intent = new Intent();
                intent.setData(Uri.parse(tempUrl));
                intent.setAction(Intent.ACTION_VIEW);
                context.startActivity(intent);
//                context.startActivity(IMActivity.queryIntent(context,AppUtils.BASE_URL + "app/cservice?userId=" + MyApplication.getInstance().userLoginBean.getUserId()));
                break;
        }

    }


    public void showPricePopup(View parent) {
        if (!this.isShowing()) {
            this.showAsDropDown(parent);
        } else {
            this.dismiss();
        }
    }


}
